﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.DTO;
using MyFloridaHouse.DataAccess.Extensions;

namespace MyFloridaHouse.DataAccess
{

    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the regions shapes in view.
        /// </summary>
        /// <param name="iZoomLevel">The i zoom level.</param>
        /// <param name="iLayerID">The i layer ID.</param>
        /// <param name="iNorth">The i north.</param>
        /// <param name="iEast">The i east.</param>
        /// <param name="iSouth">The i south.</param>
        /// <param name="iWest">The i west.</param>
        /// <returns></returns>
        public List<SQLRegionDTO> GetRegionsShapesInView(double iZoomlevel, int iLayerID, double iNorth, double iEast, double iSouth, double iWest)
        {
            List<SQLRegionDTO> itemList = new List<SQLRegionDTO>();

            //string storedProcedureName = "usp_moGetRegionsShapesInView";
            string storedProcedureName = "usp_tl10GetRegionsShapesInView10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iZoomlevel", iZoomlevel);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iLayerID", iLayerID);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("iNorth", iNorth);
                dataPartIDParm3.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm4 = StoredProcedureCommand.Parameters.AddWithValue("iEast", iEast);
                dataPartIDParm4.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm5 = StoredProcedureCommand.Parameters.AddWithValue("iSouth", iSouth);
                dataPartIDParm5.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm6 = StoredProcedureCommand.Parameters.AddWithValue("iWest", iWest);
                dataPartIDParm6.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(SQLRegionDTODataContract.DataContract(rdr));
                    }
                }
            }
            return itemList;
        }

    }
}
